//
//  TSRechargeViewController.swift
//  TSProfitProject
//
//  Created by TMS on 2019/11/4.
//  Copyright © 2019 TMS. All rights reserved.
//

import UIKit

class TSRechargeViewController: TSBaseViewController {

    let model = TSNormalCellModel.init(title: "UTSD", value: "", textColor: "#702FC9", font: UIFont.systemFont(ofSize: 14, weight: .medium))
    var tableView : UITableView!
    var headerView : TSRechargeHeaderView!
    
    override func viewDidLoad() {
        super.viewDidLoad()

        configViews()
        setupNavigationTitle(title: "充值")
    }

}

extension TSRechargeViewController : TSRechargeInfoViewControllerDelegate {
    
    func completeRecharge() {
        self.headerView.refreshHeaderView()
    }
}

extension TSRechargeViewController : UITableViewDelegate {
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        if indexPath.section == 0 {
            let vc = TSRechargeInfoViewController()
            vc.delegate = self
            navigationController?.pushViewController(vc, animated: true)
        }
    }
}

extension TSRechargeViewController : UITableViewDataSource {
    
    func numberOfSections(in tableView: UITableView) -> Int {
        return 2
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 1
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

        
        var cell : UITableViewCell?
        
        if indexPath.section == 0 {
            var normalCell = tableView.dequeueReusableCell(withIdentifier: NSStringFromClass(TSNormalTableViewCell.self)) as? TSNormalTableViewCell
            
            if normalCell == nil {
                normalCell = TSNormalTableViewCell.init(style: .default, reuseIdentifier: NSStringFromClass(TSNormalTableViewCell.self))
            }
            
            normalCell?.setupCell(model: model, last: false)
            
            cell = normalCell
            
        } else {
            var autoHeightCell = tableView.dequeueReusableCell(withIdentifier: NSStringFromClass(TSAutoHeightTableViewCell.self)) as? TSAutoHeightTableViewCell
            
            if autoHeightCell == nil {
                autoHeightCell = TSAutoHeightTableViewCell.init(style: .default, reuseIdentifier: NSStringFromClass(TSAutoHeightTableViewCell.self))
            }
            
            autoHeightCell?.setupLabel(content: getInfoContent(), topInset: 30, textColor: "#686868", fontSize: 13)
            
            cell = autoHeightCell
        }
        
        return cell!
    }
}

extension TSRechargeViewController {
    
    func configViews() {
        
        headerView = TSRechargeHeaderView.init(frame: CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: 197))
        
        tableView = UITableView.init(frame: .zero, style: .plain)
        tableView.backgroundColor = WHITE_COLOR
        tableView.delegate = self;
        tableView.dataSource = self
        tableView.separatorStyle = .none
//        self.tableView.estimatedRowHeight = 100
        self.tableView.rowHeight = UITableView.automaticDimension
        tableView.tableHeaderView = headerView
        self.view.addSubview(tableView)
        tableView.snp.makeConstraints { (make) in
            make.left.right.bottom.equalToSuperview()
            make.top.equalTo(T_NAVBARHEIGHT)
        }
    }
    
    func getInfoContent() -> String {
        return "充值步骤：\n1.在火币网购买USDT。\n2.从法币账户转入币币账户。\n3.点击提币输入USDT复制彩金彩钱包地址，输入提币数量确定。\n4.后台提交对应的USDT数量，就会有折合人民币提示，输入姓名提交。 \n重要提示：请每次充值时务必核对最新的二维码钱包地址信息！平台会不定期更换新的二维码钱包地址。如因本人原因造成的损失平台概不负责！\n温馨提示：人民币提现每日仅限1次，金额5000元以内。USDT提现无上限。"
    }
}
